package top.bigdata.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.bigdata.model.dto.DateWeeklyData;
import top.bigdata.model.dto.MonthlyData;
import top.bigdata.model.dto.Response;
import top.bigdata.model.dto.video.AvgData;
import top.bigdata.model.dto.video.DurationData;
import top.bigdata.model.entity.Video;
import top.bigdata.service.api.VideoService;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/video")
@Tag(name = "视频接口")
public class VideoController {
    private final VideoService videoService;

    @GetMapping("/getHotVideo")
    @Operation(
            summary = "获取最热视频",
            parameters = {@Parameter(name = "tid", description = "分区id，为0时获取全站视频")},
            responses = {
                    @ApiResponse(description = "成功", responseCode = "200"),
                    @ApiResponse(description = "失败", responseCode = "500")
            }
    )
    public Response<List<Video>> getHotVideo(@RequestParam(name = "tid", defaultValue = "0") int tid) {
        return Response.success(videoService.getHotVideo(tid));
    }

    @GetMapping("/getView")
    @Operation(summary = "获取分区视频平均播放量")
    public Response<List<AvgData>> getAvgView() {
        return Response.success(videoService.getAvgView());
    }

    @GetMapping("/getLike")
    @Operation(summary = "获取分区视频平均点赞数")
    public Response<List<AvgData>> getLike() {
        return Response.success(videoService.getLike());
    }

    @GetMapping("/getCoin")
    @Operation(summary = "获取分区视频平均投币数")
    public Response<List<AvgData>> getCoin() {
        return Response.success(videoService.getCoin());
    }

    @GetMapping("/getFavorite")
    @Operation(summary = "获取分区视频平均收藏数")
    public Response<List<AvgData>> getFavorite() {
        return Response.success(videoService.getFavorite());
    }

    @GetMapping("/getShare")
    @Operation(summary = "获取分区视频平均分享数")
    public Response<List<AvgData>> getShare() {
        return Response.success(videoService.getShare());
    }

    @GetMapping("/getDanmuku")
    @Operation(summary = "获取分区弹幕平均数量")
    public Response<List<AvgData>> getDanmuku() {
        return Response.success(videoService.getDanmuku());
    }

    @GetMapping("/getReply")
    @Operation(summary = "获取分区视频平均评论数")
    public Response<List<AvgData>> getReply() {
        return Response.success(videoService.getReply());
    }

    @GetMapping("/getDataMonthly")
    @Operation(
            summary = "获取分区视频各指标平均数的月度数据",
            parameters = {@Parameter(name = "tid", description = "分区id，为0时获取全站视频")}
    )
    public Response<List<MonthlyData>> getDataMonthly(@RequestParam(name = "tid", defaultValue = "0") int tid) {
        return Response.success(videoService.getDataMonthly(tid));
    }

    @GetMapping("/getDataWeekly")
    @Operation(
            summary = "获取分区视频各指标平均数的周度数据",
            parameters = {@Parameter(name = "tid", description = "分区id，为0时获取全站视频")}
    )
    public Response<List<DateWeeklyData>> getDataWeekly(@RequestParam(name = "tid", defaultValue = "0") int tid) {
        return Response.success(videoService.getDataWeekly(tid));
    }

    @GetMapping("/getDurationData")
    @Operation( summary = "获取不同时长的视频数据",
            parameters = {@Parameter(name = "tid", description = "分区id，为0时获取全站视频")}
    )
    public Response<List<DurationData>> getDurationData(@RequestParam(name = "tid", defaultValue = "0") int tid) {
        return Response.success(videoService.getDurationData(tid));
    }
}
